package com.qf.test.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.test.mapper.DtsOrderMapper;
import com.qf.test.pojo.DtsOrder;
import com.qf.test.vo.CategorySellAmts;
import com.qf.test.vo.DayStatis;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OrderServiceGoodsImpl implements OrderService {
    @Autowired
    private DtsOrderMapper orderMapper;
    @Override
    public int countOrder() {
        QueryWrapper<DtsOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",false);
        Integer count = orderMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public List<DayStatis> incrCount() {
        List<DayStatis> list = orderMapper.staticIncreasuUser();
        return list;
    }

    @Override
    public List<CategorySellAmts> categoryCount() {
        List<CategorySellAmts> list = orderMapper.categorySell();
        return list;
    }
    /**
     * 订单首页的展示
     * @return
     */
    @Override
    public IPage<DtsOrder> findfall(Integer page, Integer limit, String sort, String order, String Id, String order_Sn) {
        Page<DtsOrder> page1 = new Page<>(page,limit);
        QueryWrapper<DtsOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",false);

        if(!StringUtils.isEmpty(Id)){
            queryWrapper.like("user_id",Id);
        }
        if(!StringUtils.isEmpty(order_Sn)){
            queryWrapper.eq("order_sn",order_Sn);
        }

        if(StringUtils.isEmpty(sort)&&StringUtils.isEmpty(order)){
            if(order.equalsIgnoreCase("desc")){
                queryWrapper.orderByDesc(sort);
            }else{
                queryWrapper.orderByAsc(sort);

            }
        }
        Page<DtsOrder> page2 = orderMapper.selectPage(page1, queryWrapper);
        return page2;
    }



}
